home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / exv / SchemaStrArray.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  8.5 KB  |  440 lines

  1. package com.extensibility.exv;
  2.  
  3. import com.extensibility.util.StringUtilities;
  4. import com.extensibility.xml.BaseDeclaration;
  5. import com.extensibility.xml.ExternalSubset;
  6. import java.io.File;
  7. import java.io.IOException;
  8. import java.io.Serializable;
  9. import java.util.Enumeration;
  10. import java.util.Hashtable;
  11. import java.util.Vector;
  12.  
  13. public class SchemaStrArray extends MultiModule implements Serializable {
  14.    private static final boolean DEFAULT_PERSISTENT = true;
  15.    private Hashtable schemas;
  16.    private Hashtable used;
  17.  
  18.    public SchemaStrArray(String[] var1, String[] var2) throws SchemaException {
  19.       this(true, var1, var2);
  20.    }
  21.  
  22.    SchemaStrArray(boolean var1, String[] var2, String[] var3) throws SchemaException {
  23.       super(0, var1);
  24.       this.schemas = new Hashtable();
  25.       this.used = new Hashtable();
  26.       this.setSchemas(var2, var3);
  27.    }
  28.  
  29.    public SchemaStrArray(boolean[] var1, String[] var2, String[] var3) throws SchemaException {
  30.       this(true, var1, var2, var3);
  31.    }
  32.  
  33.    SchemaStrArray(boolean var1, boolean[] var2, String[] var3, String[] var4) throws SchemaException {
  34.       super(0, var1);
  35.       this.schemas = new Hashtable();
  36.       this.used = new Hashtable();
  37.       this.setSchemas(var2, var3, var4);
  38.    }
  39.  
  40.    public SchemaStrArray() {
  41.       this(true);
  42.    }
  43.  
  44.    SchemaStrArray(boolean var1) {
  45.       super(0, var1);
  46.       this.schemas = new Hashtable();
  47.       this.used = new Hashtable();
  48.  
  49.       try {
  50.          ((MultiModule)this).setMap(0, true);
  51.       } catch (SchemaException var3) {
  52.       }
  53.  
  54.    }
  55.  
  56.    public void setSchemas(String[] var1, String[] var2) throws SchemaException {
  57.       if (var1 != null && var2 != null) {
  58.          ((MultiModule)this).setMap(var1.length, true);
  59.          ((MultiModule)this).initFileNameMap(var1);
  60.  
  61.          try {
  62.             this.initSchemas(var1, var2);
  63.          } catch (Exception var4) {
  64.             throw new SchemaException("Could not create multi modules of schema", var4);
  65.          }
  66.       } else {
  67.          throw new SchemaException("Invalid schemas");
  68.       }
  69.    }
  70.  
  71.    public void setSchemas(boolean[] var1, String[] var2, String[] var3) throws SchemaException {
  72.       if (var1 != null && var2 != null && var3 != null) {
  73.          ((MultiModule)this).setMap(var1);
  74.          ((MultiModule)this).initFileNameMap(var2);
  75.  
  76.          try {
  77.             this.initSchemas(var1, var2, var3);
  78.          } catch (Exception var5) {
  79.             throw new SchemaException("Could not create multi modules of schema", var5);
  80.          }
  81.       } else {
  82.          throw new SchemaException("Invalid schemas");
  83.       }
  84.    }
  85.  
  86.    public int countFlavor(String var1) {
  87.       Enumeration var2 = this.schemas.keys();
  88.       int var3 = 0;
  89.  
  90.       while(var2.hasMoreElements()) {
  91.          String var4 = (String)var2.nextElement();
  92.          if (var4.toLowerCase().endsWith(String.valueOf(".").concat(String.valueOf(var1.toLowerCase())))) {
  93.             ++var3;
  94.          }
  95.       }
  96.  
  97.       return var3;
  98.    }
  99.  
  100.    public Vector getSchemas() {
  101.       return this.getSchemas(this.schemas);
  102.    }
  103.  
  104.    public SchemaWrapper getSchema(String var1) {
  105.       SchemaWrapper var2;
  106.       return (var2 = (SchemaWrapper)this.schemas.get(var1)) == null ? null : var2;
  107.    }
  108.  
  109.    public void validate() {
  110.       super.validValues = new Hashtable();
  111.       super.wfValues = new Hashtable();
  112.       super.errors = new Hashtable();
  113.       Enumeration var1 = this.schemas.keys();
  114.  
  115.       while(var1.hasMoreElements()) {
  116.          String var2 = (String)var1.nextElement();
  117.          if (!this.used.containsKey(var2)) {
  118.             try {
  119.                this.validate(var2);
  120.             } catch (Exception var4) {
  121.             }
  122.          }
  123.       }
  124.  
  125.    }
  126.  
  127.    public void validate(String var1) throws SchemaException {
  128.       if (var1 == null) {
  129.          throw new SchemaException("Cannot validate a null schema");
  130.       } else if (!this.schemas.containsKey(var1)) {
  131.          throw new SchemaException("Schema not found in archive");
  132.       } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
  133.          throw new SchemaException("Schema is not parseable");
  134.       } else {
  135.          if (!this.used.containsKey(var1)) {
  136.             SchemaWrapper var2 = (SchemaWrapper)this.schemas.get(var1);
  137.             this.validateSchema(var1, var2);
  138.          }
  139.  
  140.       }
  141.    }
  142.  
  143.    public boolean isValid() throws SchemaException {
  144.       if (((MultiModule)this).isEmpty()) {
  145.          throw new SchemaException("There are no schemas in the archive");
  146.       } else {
  147.          Vector var1 = this.getSchemas();
  148.  
  149.          for(int var2 = 0; var2 < var1.size(); ++var2) {
  150.             SchemaWrapper var3 = (SchemaWrapper)var1.elementAt(var2);
  151.             if (super.map[((MultiModule)this).getIndexOfSchema(var3.getFileName())] && !var3.isValid()) {
  152.                return false;
  153.             }
  154.          }
  155.  
  156.          return true;
  157.       }
  158.    }
  159.  
  160.    public boolean isValid(String var1) throws SchemaException {
  161.       if (!this.schemas.containsKey(var1)) {
  162.          throw new SchemaException("Schema not found in archive.");
  163.       } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
  164.          throw new SchemaException("Schema is not parseable");
  165.       } else {
  166.          return ((SchemaWrapper)this.schemas.get(var1)).isValid();
  167.       }
  168.    }
  169.  
  170.    public boolean isWellFormed() throws SchemaException {
  171.       if (((MultiModule)this).isEmpty()) {
  172.          throw new SchemaException("There are no schemas in the archive");
  173.       } else {
  174.          Vector var1 = this.getSchemas();
  175.  
  176.          for(int var2 = 0; var2 < var1.size(); ++var2) {
  177.             SchemaWrapper var3 = (SchemaWrapper)var1.elementAt(var2);
  178.             if (super.map[((MultiModule)this).getIndexOfSchema(var3.getFileName())] && !var3.isWellFormed()) {
  179.                return false;
  180.             }
  181.          }
  182.  
  183.          return true;
  184.       }
  185.    }
  186.  
  187.    public boolean isWellFormed(String var1) throws SchemaException {
  188.       if (!this.schemas.containsKey(var1)) {
  189.          throw new SchemaException("Schema not found in archive.");
  190.       } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
  191.          throw new SchemaException("Schema is not parseable");
  192.       } else {
  193.          return ((SchemaWrapper)this.schemas.get(var1)).isWellFormed();
  194.       }
  195.    }
  196.  
  197.    public Vector getValidSchemas() {
  198.       Vector var1 = new Vector();
  199.       Vector var2 = this.getUsedSchemas();
  200.  
  201.       for(int var3 = 0; var3 < var2.size(); ++var3) {
  202.          SchemaWrapper var4 = (SchemaWrapper)var2.elementAt(var3);
  203.          if (super.map[((MultiModule)this).getIndexOfSchema(var4.getFileName())] && var4.isValid()) {
  204.             var1.addElement(var4);
  205.          }
  206.       }
  207.  
  208.       return var1;
  209.    }
  210.  
  211.    public Vector getNotValidSchemas() {
  212.       Vector var1 = new Vector();
  213.       Vector var2 = this.getUsedSchemas();
  214.  
  215.       for(int var3 = 0; var3 < var2.size(); ++var3) {
  216.          SchemaWrapper var4 = (SchemaWrapper)var2.elementAt(var3);
  217.          if (super.map[((MultiModule)this).getIndexOfSchema(var4.getFileName())] && !var4.isValid()) {
  218.             var1.addElement(var4);
  219.          }
  220.       }
  221.  
  222.       return var1.size() == 0 ? null : var1;
  223.    }
  224.  
  225.    public Vector getWfSchemas() {
  226.       Vector var1 = new Vector();
  227.       Vector var2 = this.getUsedSchemas();
  228.  
  229.       for(int var3 = 0; var3 < var2.size(); ++var3) {
  230.          SchemaWrapper var4 = (SchemaWrapper)var2.elementAt(var3);
  231.          if (super.map[((MultiModule)this).getIndexOfSchema(var4.getFileName())] && var4.isWellFormed()) {
  232.             var1.addElement(var4);
  233.          }
  234.       }
  235.  
  236.       return var1;
  237.    }
  238.  
  239.    public Vector getNotWfSchemas() {
  240.       Vector var1 = new Vector();
  241.       Vector var2 = this.getUsedSchemas();
  242.  
  243.       for(int var3 = 0; var3 < var2.size(); ++var3) {
  244.          SchemaWrapper var4 = (SchemaWrapper)var2.elementAt(var3);
  245.          if (super.map[((MultiModule)this).getIndexOfSchema(var4.getFileName())] && !var4.isWellFormed()) {
  246.             var1.addElement(var4);
  247.          }
  248.       }
  249.  
  250.       return var1;
  251.    }
  252.  
  253.    public Vector getNotParseable() {
  254.       Vector var1 = new Vector(((MultiModule)this).getNotParseableCount());
  255.  
  256.       for(int var2 = 0; var2 < super.map.length; ++var2) {
  257.          if (!super.map[var2]) {
  258.             var1.addElement(this.schemas.get(super.fileNameMap[var2]));
  259.          }
  260.       }
  261.  
  262.       return var1;
  263.    }
  264.  
  265.    public Vector getDeclErrors(String var1) throws SchemaException {
  266.       if (!this.schemas.containsKey(var1)) {
  267.          throw new SchemaException("Schema not found in archive");
  268.       } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
  269.          throw new SchemaException("Schema is not parseable");
  270.       } else {
  271.          return ((MultiModule)this).retDeclErrors(var1);
  272.       }
  273.    }
  274.  
  275.    public int getDeclErrorsCount(String var1) throws SchemaException {
  276.       if (!this.schemas.containsKey(var1)) {
  277.          throw new SchemaException("Schema not found in archive");
  278.       } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
  279.          throw new SchemaException("Schema is not parseable");
  280.       } else {
  281.          return ((MultiModule)this).retDeclErrorsCount(var1);
  282.       }
  283.    }
  284.  
  285.    public Vector getParseErrors(String var1) throws SchemaException {
  286.       if (!this.schemas.containsKey(var1)) {
  287.          throw new SchemaException("Schema not found in archive");
  288.       } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
  289.          throw new SchemaException("Schema is not parseable");
  290.       } else {
  291.          return ((MultiModule)this).retParseErrors(var1);
  292.       }
  293.    }
  294.  
  295.    public int getParseErrorsCount(String var1) throws SchemaException {
  296.       if (!this.schemas.containsKey(var1)) {
  297.          throw new SchemaException("Schema not found in archive");
  298.       } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
  299.          throw new SchemaException("Schema is not parseable");
  300.       } else {
  301.          return ((MultiModule)this).retParseErrorsCount(var1);
  302.       }
  303.    }
  304.  
  305.    public Vector getDeclErrorsDesc(String var1) throws SchemaException {
  306.       if (!this.schemas.containsKey(var1)) {
  307.          throw new SchemaException("Schema not found in archive");
  308.       } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
  309.          throw new SchemaException("Schema is not parseable");
  310.       } else {
  311.          return ((MultiModule)this).retDeclErrorsDesc(var1);
  312.       }
  313.    }
  314.  
  315.    public Vector getParseErrorsDesc(String var1) throws SchemaException {
  316.       if (!this.schemas.containsKey(var1)) {
  317.          throw new SchemaException("Schema not found in archive");
  318.       } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
  319.          throw new SchemaException("Schema is not parseable");
  320.       } else {
  321.          return ((MultiModule)this).retParseErrorsDesc(var1);
  322.       }
  323.    }
  324.  
  325.    public String getResults(String var1) throws SchemaException {
  326.       if (!this.schemas.containsKey(var1)) {
  327.          throw new SchemaException("Schema not found in archive");
  328.       } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
  329.          throw new SchemaException("Schema is not parseable");
  330.       } else {
  331.          return ((SchemaWrapper)this.schemas.get(var1)).getResults();
  332.       }
  333.    }
  334.  
  335.    void changedSchema(String var1) {
  336.       if (this.used.containsKey(var1)) {
  337.          this.used.remove(var1);
  338.       }
  339.  
  340.    }
  341.  
  342.    private void initSchemas(boolean[] var1, String[] var2, String[] var3) throws IOException, SchemaException {
  343.       if (var1.length != var2.length) {
  344.          throw new SchemaException("The <Map> array and the <FileName> array must have the same size");
  345.       } else {
  346.          this.initSchemas(var2, var3);
  347.       }
  348.    }
  349.  
  350.    private void initSchemas(String[] var1, String[] var2) throws IOException, SchemaException {
  351.       this.used = new Hashtable();
  352.       if (var1.length != var2.length) {
  353.          throw new SchemaException("The <FileName> array and the <Content> array must have the same size");
  354.       } else {
  355.          for(int var3 = 0; var3 < var1.length; ++var3) {
  356.             var2[var3] = var2[var3].substring(StringUtilities.skipWhite(var2[var3], 0));
  357.          }
  358.  
  359.          if (super.persistent) {
  360.             ((MultiModule)this).saveToFile(var1, var2);
  361.          }
  362.  
  363.          this.createSchemas(var1, var2);
  364.       }
  365.    }
  366.  
  367.    private void createSchemas(String[] var1, String[] var2) {
  368.       for(int var3 = var1.length - 1; var3 >= 0; --var3) {
  369.          try {
  370.             this.schemas.put(var1[var3], new SchemaWrapper(new File(super.localDir, var1[var3]), this));
  371.          } catch (Exception var5) {
  372.             this.schemas.put(var1[var3], (Object)null);
  373.          }
  374.       }
  375.  
  376.    }
  377.  
  378.    private Vector getUsedSchemas() {
  379.       return this.getSchemas(this.used);
  380.    }
  381.  
  382.    private Vector getSchemas(Hashtable var1) {
  383.       Vector var2 = new Vector(var1.size());
  384.       Enumeration var3 = var1.elements();
  385.  
  386.       while(var3.hasMoreElements()) {
  387.          var2.addElement(var3.nextElement());
  388.       }
  389.  
  390.       return var2;
  391.    }
  392.  
  393.    private void validateSchema(String var1, SchemaWrapper var2) {
  394.       this.validateSchema0(var1, var2);
  395.       this.validateInclMod(var2);
  396.    }
  397.  
  398.    private void validateSchema0(String var1, SchemaWrapper var2) {
  399.       try {
  400.          if (!this.used.containsKey(var1)) {
  401.             this.used.put(var1, var2);
  402.          }
  403.  
  404.          var2.validate();
  405.          super.validValues.put(var1, new Boolean(var2.isValid()));
  406.          super.wfValues.put(var1, new Boolean(var2.isWellFormed()));
  407.          SchemaAllErrors var3 = new SchemaAllErrors();
  408.          if (!var2.isValid()) {
  409.             var3.setDeclErrors(var2.getDeclErrors());
  410.             var3.setParseErrors(var2.getParseErrors());
  411.             var3.setDeclErrorsDesc(var2.getDeclErrorsDesc());
  412.             var3.setParseErrorsDesc(var2.getParseErrorsDesc());
  413.          }
  414.  
  415.          super.errors.put(var1, var3);
  416.       } catch (Exception var4) {
  417.          super.validValues.put(var1, new Boolean(false));
  418.          super.wfValues.put(var1, new Boolean(false));
  419.       }
  420.  
  421.    }
  422.  
  423.    private void validateInclMod(SchemaWrapper var1) {
  424.       Vector var2 = new Vector(((MultiModule)this).size() - 1);
  425.       Enumeration var3 = var1.getIncludedModules();
  426.       if (var3 != null) {
  427.          while(var3.hasMoreElements()) {
  428.             ExternalSubset var4 = (ExternalSubset)var3.nextElement();
  429.             String var5 = ((BaseDeclaration)var4).getName();
  430.             if (!var2.contains(var5)) {
  431.                var2.addElement(var5);
  432.                SchemaWrapper var6 = (SchemaWrapper)this.schemas.get(var5);
  433.                this.validateSchema0(var5, var6);
  434.             }
  435.          }
  436.       }
  437.  
  438.    }
  439. }
  440.